package com.nc.mem.tests.custom.map;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

import org.testng.Assert;

import com.nc.mem.serial.graph.cust.Serializable;

@Serializable(include = "*")
public class D extends AbstractMapSource {

	static Comparator<String> C5 = new Comparator<String>() {

		Comparator<String> c;

		{
			c = this;
		}

		@Override
		public int compare(final String left, final String right) {
			if (c != this) {
				return c.compare(left, right);
			}
			return left.compareTo(right);
		}
	};
	Map<String, A> cacheAC = new TreeMap<String, A>(C5);

	Map<String, A> cacheAD = new TreeMap<String, A>(C5);

	public void assertAllCachesSized(final int i) {
		for (final Map<?, ?> m : getAllCaches()) {
			Assert.assertEquals(i, m.size());
		}
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final D other = (D) obj;

		final Map<?, ?>[] maps = getAllCaches();
		final Map<?, ?>[] otherMaps = other.getAllCaches();

		for (int i = 0; i < maps.length; i++) {
			if (!maps[i].equals(otherMaps[i])) {
				return false;
			}
		}

		return true;

	}

	@SuppressWarnings("unchecked")
	public void fill(final Iterable<A> itr) {
		final Map<?, ?>[] caches = getAllCaches();
		for (final A a : itr) {
			for (@SuppressWarnings("rawtypes")
			final Map map : caches) {
				map.put(a.id, a);
				map.put(a.id + "clone", a.clone());
			}
		}
	}

	@Override
	public int hashCode() {
		return 0;
	}

}
